<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("conn.php");
$current_year = date("Y", time());
$current_month = date("n", time());
$year = $current_year;
$month = $current_month;
$age = 3;
$packid = "";
$product_info = "&nbsp;";
if (isset($_GET['packid'])) {
    $packid = $_GET['packid'];
    $db = new DBC();
    $sql = "SELECT * FROM t_pack WHERE packid = " . $_GET['packid'];
    $data = $db->fetchData($sql);
    if (count($data) > 0) {
        $year = $data[0]['year'];
        $month = $data[0]['month'];
        $age = $data[0]['age'];
        $packcode = $data[0]['packcode'];
        $name = $data[0]['name'];
        $soundURL = $data[0]['soundURL'];
        $ImageAid1URL = $data[0]['ImageAid1URL'];
        $ImageAid2URL = $data[0]['ImageAid2URL'];
        $imageURL = $data[0]['imageURL'];
    }
    $product_age = -1;
    $sql = "SELECT * FROM t_product WHERE packid = " . $packid;
    $products = $db->fetchData($sql);

    foreach ($products as $p) {
        $product_info .= $p['flashcode'] . "-" . $p['name'] . " ";
        $product_age = $p['age'];
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>乐知家园</title>
        <script language="javascript">
            function change_age(e){
                var selopt = e.options[e.selectedIndex].value;
                var product_age = document.getElementById("product_age").value;
                if(selopt!=product_age&&product_age!=-1&&product_age!=''){
                    alert("\u5957的年龄和所拥有的应用不一致");
                    e.options[product_age].selected = true;   
                }                        
            }
        </script>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 12px;
                color: #CCCCCC;
            }

            .text{
                height:20px; 
            }
            .disable{
                background-color:#CCCCCC;
            }
            -->
        </style></head>

    <body>
        <?php
        if (!isset($packcode)) {
            $packcode = "";
        }
        if (!isset($name)) {
            $name = "";
        }
        if (!isset($soundURL)) {
            $soundURL = "";
        }
        if (!isset($ImageAid1URL)) {
            $ImageAid1URL = "";
        }
        if (!isset($ImageAid2URL)) {
            $ImageAid2URL = "";
        }
        if (!isset($imageURL)) {
            $imageURL = "";
        }
        ?>        
        <br/>
        <form id="form1" name="form1" method="post" action="pack.action.php" enctype="multipart/form-data">
            <table width="50%" border="0" align="center" cellpadding="1" cellspacing="1">
                <tr>
                    <td height="30" bgcolor="#666666">ID</td>
                    <td bgcolor="#9999FF"><input name="packid" type="text" size="50" class="disable" value="<?php echo $packid; ?>" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">编号
                        <input name="packid" type="hidden" value="<?php echo $packid; ?>"/></td>
                    <td bgcolor="#9999FF"><input name="packcode" type="text" size="50" class="text" value="<?php echo $packcode; ?>" /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666"> 套名</td>
                    <td bgcolor="#9999FF"><input name="name" type="text" size="50" class="text" value="<?php echo $name; ?>" /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">年龄<input name="product_age" id="product_age" type="hidden" value="<?php echo $product_age; ?>" /></td>
                    <td bgcolor="#9999FF"><label>
                            <select name="age" onchange="change_age(this);">
                                <?php for ($a = 0; $a < 6; $a++) { ?>
                                    <option value="<?php echo $a; ?>" <?php if ($a == $age) { ?>selected<?php } ?>><?php echo $a . "-" . ($a + 1) . "岁"; ?></option>
                                <?php } ?>
                            </select>
                        </label></td>
                </tr>s                
                <tr>
                    <td height="30" bgcolor="#666666">语音</td>
                    <td bgcolor="#9999FF"><input name="soundURL" type="file" size="50" class="text" value="<?php echo $soundURL; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">包含应用</td>
                    <td bgcolor="#9999FF"><?php echo $product_info; ?></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">月份</td>
                    <td bgcolor="#9999FF"><label>
                            <select name="month">
                                <option value="-1">无</option>
                                <?php for ($m = 1; $m < 13; $m++) { ?>
                                    <option value="<?php echo $m; ?>" <?php if ($m == $month) { ?>selected<?php } ?>><?php echo $m; ?></option>
                                <?php } ?>
                            </select>
                        </label></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">年份</td>
                    <td bgcolor="#9999FF"><label>
                            <select name="year">
                                <option value="-1">无</option>
                                <?php for ($y = 2012; $y < $current_year + 4; $y++) { ?>
                                    <option value="<?php echo $y; ?>" <?php if ($y == $year) { ?>selected<?php } ?>><?php echo $y; ?></option>
                                <?php } ?>                                    
                            </select>
                        </label></td>
                </tr>                
                <tr>
                    <td height="30" bgcolor="#666666">&nbsp;</td>
                    <td bgcolor="#9999FF"><label>
                            <input type="submit" name="Submit" value="提交" />
                        </label></td>
                </tr>
            </table>
        </form>
    </body>
</html>
<?php
include_once 'footer.php';
//} else {
//    header("login.php");
//}
?>